package com.acme.bankapp.domain.bank.client;

import java.io.Serializable;

/**
 * This class represents client id (name and gender)
 *
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */
public class ClientInfo implements Serializable {
    private final Gender gender;
    private final String name;
    private final String emailAddress;

    public ClientInfo(Gender gender, String name) {
        this(gender, name, null);
    }

    public ClientInfo(Gender gender, String name, String emailAddress) {
        this.gender = gender;
        this.name = name;
        this.emailAddress = emailAddress;
    }

    public Gender getGender() {
        return gender;
    }

    public String getName() {
        return name;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    @Override
    public String toString() {
        return gender.getSalutation() + " " + name;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }

        ClientInfo clientInfo = (ClientInfo) obj;

        if (gender != clientInfo.gender) {
            return false;
        }

        if (name != null) {
            if (!name.equals(clientInfo.name)) {
                return false;
            }
        } else if (clientInfo.name != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = 0;
        if (name != null) {
            result = name.hashCode();
        }
        int genderHashCode = 0;
        if (gender != null) {
            genderHashCode = gender.hashCode();
        }
        result = 31 * result + genderHashCode;
        return result;
    }
}
